﻿Ext.define("PSI.InPlan.Report", {

    createToolButtons: function () {
        var me = this;
        var p = me.permission;
        var result = [];
        //result.push("-");
        //result.push({ text: "刷新", iconCls: "psi-button-refresh", handler: me.onRefreshPlanGird, scope: me });
        //result.push("-");
        //result.push({ text: "导出Excel", iconCls: "psi-button-excel", handler: me.onExcel, scope: me });
        //result.push("-");
        result.push({
            text: "关闭", iconCls: "psi-button-exit", handler: function () {
                if (me.qc && (me.qc.billNumber || me.qc.planNumber)) {
                    if (Ext.isChrome) {
                        window.open("", "_self", "");
                        window.close();
                    } else if (Ext.isIE) {
                        window.close();
                    } else {
                        location.replace("/");
                    }
                } else {
                    location.replace("/");
                }
            }
        });
        return result;
    },

    createUI: function () {
        var me = this;

        var panel = Ext.create("Ext.panel.Panel", {
            border: 0,
            layout: "border",
            title: "进口计划查询",
          //  tbar: me.createToolButtons(),
            items: [{
                region: "north", xtype: "container",
                height:30,
                layout: {
                    type: "table",
                    columns: 4
                }, border: false,
                items: [ {
                    xtype: "label",
                    text: "计划下达日期:"
                },{
                    xtype: "datefield",
                    margin: "4 5 0 5",
                    format: "Y-m-d",
                    width: 170,
                    id: "editPlanDT1QC"
                }, 
                
                {
                    xtype: "button",
                    text: "查询",
                    iconCls: "psi-button-refresh",
                    margin: "4 5 0 5",
                    width: 90,
                    handler: me.onRefreshPlanGird,
                    scope: me
                }
           
                ]
            },
                {
                    region: "center", xtype: "container", layout: "fit", border: false,
                    items: [me.getInPlanGrid()]
                }
            ]
        });

        me.panel = panel;
    },

    getMainPanel: function () {
        return this.panel;
    },

    getInPlanGrid: function () {
        var me = this;

        if (!me.__inPlanGrid) {
            me.__inPlanGrid = me.createInPlanGrid();
        }

        return me.__inPlanGrid;
    },

    createInPlanGrid: function () {
        var modelName = "PSIInPlanModel";
        Ext.define(modelName, {
            extend: "Ext.data.Model",
            fields: ["Address", "CntOwner", "CntType1", "CntType2", "Memo"]
        });

        return Ext.create("Ext.grid.Panel", {
            viewConfig: { enableTextSelection: true, loadingText: "数据加载中...." },
            columnLines: true,
            columns: [
                    Ext.create("Ext.grid.RowNumberer", { text: "序号", width: 30 }),
                    { header: "门点", dataIndex: "Address", menuDisabled: true },
                    { header: "箱属", dataIndex: "CntOwner", menuDisabled: true },
                    { header: "20GP", dataIndex: "CntType1", menuDisabled: true },
                    { header: "40HP", dataIndex: "CntType2", menuDisabled: true },
                    { header: "备注", dataIndex: "Memo", menuDisabled: true }
            ],
            store: Ext.create("Ext.data.Store", {
                autoLoad: false,
                model: modelName,
                storeId: 'kRreply',
                proxy: {
                    type: 'ajax',
                    url: '/InPlan/GetImReport',
                    extraParams: {dt:Ext.Date.format(new Date(), "Y-m-d")},
                    actionMethods: { read: 'POST' },
                    reader: {
                        type: 'json',
                        root: 'Data'
                    }
                },
                autoLoad: true,
                listeners: {
                    load: function (me, records, successful, eOpts) {

                    }
                }
            })
        });
    },

    onRefreshPlanGird: function ()
    {
        var store = Ext.data.StoreManager.lookup('kRreply');

        var jhst = Ext.getCmp("editPlanDT1QC").getValue();

        if (jhst != ""&&jhst!=null) {
            store.load({
                params: { dt: jhst }
            });
        }
    }
});